package com.twu.biblioteca.Command;

import com.twu.biblioteca.Bibilioteca;
import com.twu.biblioteca.BibiliotecaModel;

public class MenuHandler {
    private Bibilioteca bibilioteca;

    public MenuHandler(Bibilioteca bibilioteca) {
        this.bibilioteca = bibilioteca;
    }

    private IBibiliotecaCommand selected;

    public void selectMenu() {
        int menuOpt;
        do {
            if (!bibilioteca.getScanner().hasNext())
                break;
            menuOpt = bibilioteca.getScanner().nextInt();
            if (menuOpt == -1) break;
            switch (menuOpt) {
                case 1:
                    selected = new ShowBooksCommand();
                    break;
                case 2:
                    selected = new ReserveBookCommand(bibilioteca);
                    break;
                case 3:
                    selected = new ShowMembershipDetailCommand(bibilioteca);
                    break;
                case 4:
                    selected = new ShowAllMoviesCommand();
                    break;
                case 5:
                    selected = new LoginCommand(bibilioteca);
                    break;
                default:
                    bibilioteca.getOutputBuffter().println("You selected an invalid option!");
                    break;
            }
            if (selected != null) {
                bibilioteca.getOutputBuffter().println("You selected" + " " + BibiliotecaModel.getMenuOptions().get(menuOpt - 1).toString());
                selected.ICommand(bibilioteca.getOutputBuffter());
            }
        } while (true);
    }

}


